﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Robotics.Race
{
	[ShortName("Keyboard")]
	public class KeyboardController : Controller
	{
		public KeyboardController()
		{
		}

		public override void Drive( SensedEnvironment environment, ControlGear gear )
		{
			int acceleration = 0;
			if ( Keyboard.IsPressed( ForwardKey ) )
				++acceleration;
			if ( Keyboard.IsPressed( BackwardKey ) )
				--acceleration;
			gear.Acceleration = acceleration;

			int turn = 0;
			if ( Keyboard.IsPressed( LeftKey ) )
				--turn;
			if ( Keyboard.IsPressed( RightKey ) )
				++turn;
			gear.Steering = turn;

			gear.Handbrake = Keyboard.IsPressed( HandbrakeKey );
		}

		[System.ComponentModel.Category( "Keys" )]
		Keys forwardKey = Keys.Up;
		public Keys ForwardKey { get { return forwardKey; } set { forwardKey = value; } }
		[System.ComponentModel.Category( "Keys" )]
		Keys backwardKey = Keys.Down;
		public Keys BackwardKey { get { return backwardKey; } set { backwardKey = value; } }
		[System.ComponentModel.Category( "Keys" )]
		Keys leftKey = Keys.Left;
		public Keys LeftKey { get { return leftKey; } set { leftKey = value; } }
		[System.ComponentModel.Category( "Keys" )]
		Keys rightKey = Keys.Right;
		public Keys RightKey { get { return rightKey; } set { rightKey = value; } }
		[System.ComponentModel.Category( "Keys" )]
		Keys handbrakeKey = Keys.Space;
		public Keys HandbrakeKey { get { return handbrakeKey; } set { handbrakeKey = value; } }
	}
}
